#ifndef SETTINGDIALOG_H
#define SETTINGDIALOG_H

#include <QDialog>
#include "machineparam.h"
#include <QtSerialPort/QSerialPort>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDial>
#include <QtWidgets/QDialog>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QWidget>

class QLabel;
class JoystickWidget;

class SpeedMonitorWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SpeedMonitorWidget(QWidget *parent = nullptr);
    ~SpeedMonitorWidget();

    bool eventFilter(QObject *, QEvent *) override;

private slots:
    void on_btn_connect_clicked();
    void onConnectResult(bool);

    void onLeftSpeedChanged(int value);
    void onRightSpeedChanged(int value);
    void onTurnLeft();
    void onTurnRight();
    void onPowerChange();//开关机
    void onEmergency();//急停
    void onLightChange();
    void onSetDirection(Direction direction);
    void onReadResult(MachineReadParam p);

    void onShowTips(QString &msg);

    void updateComPort();
    void openSerialPort();
    void readSerialDate();
    void onClickLader();
    void onSerialError(QSerialPort::SerialPortError);
    void onPortChange(const QString &portName);




signals:
    void sigAddMachineAddr(int id, QString ip, uint port);

private:
    void createConnect();
    QString getDirectionStr(Direction d);
    void initUI();


private:
    bool m_startBtnState;
    JoystickWidget * m_joyStick;
    QLabel * m_lb_direction;
    bool m_isEmergency;

    QSerialPort *m_serial;


    QSpinBox *id;
    QLineEdit *ip;
    QLineEdit *port;

    QPushButton *btn_connect;
    QLabel *tips;

    QPushButton *btnLader;
    QComboBox *comboBox;
    QPushButton *btnSerialConnect;

    QWidget *control_widget;



    QLabel *l_rightspeed;
    QDial *dial_rightspeed;

    QLabel *lb_leftspeed_val;
    QDial *dial_motorspeed;

    QLabel *lb_motorspeed_val;
    QDial *dial_leftspeed;
    QLabel *lb_rightspeed_val;


    QPushButton *btn_turn_left;
    QPushButton *btn_turn_right;

    QPushButton *btn_light;
    QPushButton *btn_start;

    QPushButton *btn_emergency_stop;
    QWidget *w_joyStick;
};

#endif // SETTINGDIALOG_H
